import { useEffect } from "react";
export const useFetch = service => app => {
  useEffect(() => {
    app.ctx.request = {
      params: {},
      shouldRequest: true
    };
  }, []);
  return {
    middlewares: async (ctx, next) => {
      // if (ctx.request.shouldRequest) {
      ctx.setState("loading");
      console.log(
        "%c 发送网络请求了 ",
        "font-size:20px;background-color: #93C0A4;color:#fff;"
      );
      ctx.res = await service();
      ctx.setState("success");
      // }
      await next();
    }
  };
};
